﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace NewGame
{
    public class Fighter
    {
        public enum STATE
        {
            RUN, IDLE
        }

        #region Attributes
        /**********************************************************************/
        protected Vector3 _position = Vector3.Zero;
        protected float _lookRotationY = 0;
        protected float _lookRotationZ = 0;
        protected float _rotationY = 0;
        protected float _speed = 2;
        private STATE _state = STATE.IDLE;
        /**********************************************************************/
        #endregion

        #region Propertises
        /**********************************************************************/
        public float LookRotationY
        {
            get { return _lookRotationY; }
            set
            {
                _lookRotationY = value;
                if (_lookRotationY > MathHelper.TwoPi)
                {
                    _lookRotationY -= MathHelper.TwoPi;
                }
                else if (_lookRotationY < 0)
                {
                    _lookRotationY += MathHelper.TwoPi;
                }
            }
        }

        public float LookRotationZ
        {
            get { return _lookRotationZ; }
            set
            {
                _lookRotationZ = value;
                if (_lookRotationZ > MathHelper.TwoPi)
                {
                    _lookRotationZ -= MathHelper.TwoPi;
                }
                else if (_lookRotationZ < 0)
                {
                    _lookRotationZ += MathHelper.TwoPi;
                }
            }
        }

        public Vector3 Position
        {
            get { return _position; }
            set { _position = value; }
        }

        public float RotationY
        {
            get { return _rotationY; }
            set { _rotationY = value; }
        }

        public STATE State
        {
            get { return _state; }
            set { _state = value; }
        }
        /**********************************************************************/
        #endregion

        #region Public Methods
        /**********************************************************************/
        public void Run()
        {
            _state = STATE.RUN;            
        }

        public void Idle()
        {
            _state = STATE.IDLE;
        }

        public void Update(GameTime gameTime)
        {
            switch (_state)
            {
                case STATE.RUN:
                    Position += new Vector3((float)(_speed * (Math.Sin(LookRotationY))), 0, (float)(_speed * (Math.Cos(LookRotationY))));
                    Vector3 newPos = Position;
                    newPos.Y = 50;
                    Position = newPos;
                    break;
                case STATE.IDLE:
                    break;
            }
        }

        public void Update(GameTime gameTime, MapTile map)
        {
            switch (_state)
            {
                case STATE.RUN:
                    Position += new Vector3((float)(_speed * (Math.Sin(LookRotationY))), 0, (float)(_speed * (Math.Cos(LookRotationY))));
                    Vector3 newPos = Position;
                    newPos.Y = map.getHeight(Position) + 10;
                    Position = newPos;
                    break;
                case STATE.IDLE:
                    break;
            }
        }
        /**********************************************************************/        
        #endregion

        #region Private Methods
        /**********************************************************************/

        /**********************************************************************/
        #endregion
    }
}
